
import CryptoJS from 'crypto-js';
import {format} from 'date-fns';

export const generateSignature=(apiKey:string,apiSecret:string,host:string,date:string)=>{
    const algorithm='hmac-sha256';
    const headers='host date request-line';
    const signatureStr=`host: ${host}\ndate:${date}\nGET/v2/iat HTTP/1.1`;
    const digest=CryptoJS.HmacSHA256(signatureStr,apiSecret);
    const signature=digest.toString(CryptoJS.enc.Base64);
    return `api_key="${apiKey}", algorithm="${algorithm}",headers="${headers}",signature="${signature}"`;

};
export const getDate=()=>{
    return  format(new Date(),"EEE,dd MMM yyyy HH:mm:ss 'GMT'",{
        locale:{
            //英文环境，满足科大讯飞日期格式要求
            months:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
            weekdays:['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
        }
    })
};